#include <gtk/gtk.h>
GtkWidget		*image;
int	toggleChange;

void on_BT_EXIT_clicked( GtkWidget *widget, gpointer   data );
void on_togglebutton1_toggled();
//void menu_quit();

int main (int argc, char *argv[])
{
    GtkBuilder      *builder;
    GtkWidget       *window;
	 GtkWidget 		*vbox1;
	GtkWidget 			*menubar,*imagemenuitem;
//	GtkWidget			*image;
    GtkWidget       *button_exit;
	GtkWidget       *togglebutton1;

    gtk_init (&argc, &argv);

// 初始化GtkBuilder，读取 UI 文件（由glade生成） 
    builder = gtk_builder_new ();
    gtk_builder_add_from_file (builder, "../glade/test.glade", NULL);

/* 自动关联已在 UI 文件配置好的信号*/
	gtk_builder_connect_signals (builder, NULL); 

//根据 ID 获取子构件
    window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
//	vbox1	=	GTK_WIDGET(gtk_builder_get_object(builder,"box1"));
	menubar	 =	GTK_WIDGET(gtk_builder_get_object(builder,"menubar1"));
//	imagemenuitem	 =	GTK_WIDGET(gtk_builder_get_object(builder,"imagemenuitem5"));
	image	=	GTK_WIDGET (gtk_builder_get_object (builder, "image1"));
	button_exit = GTK_WIDGET (gtk_builder_get_object (builder, "BT_EXIT"));
	togglebutton1 = GTK_WIDGET (gtk_builder_get_object (builder, "togglebutton1"));   

// 将 BT_EXIT 按钮的 "clicked" 事件与 on_BT_EXIT_clicked 函数关联
	g_signal_connect(button_exit,"clicked",G_CALLBACK(on_BT_EXIT_clicked),NULL);
//	g_signal_connect(button_exit,"activate",G_CALLBACK(gtk_main_quit),NULL);

//将 togglebutton1 按钮的 "toggled" 事件与 on_togglebutton1_released 函数关联
	g_signal_connect(togglebutton1,"toggled",G_CALLBACK(on_togglebutton1_toggled),NULL);

    g_object_unref (G_OBJECT (builder));
       
    gtk_widget_show_all(window);               
    gtk_main ();
 
    return 0;
}

void on_BT_EXIT_clicked( GtkWidget *widget, gpointer   data )
{	
	printf("BT_exit\n");
    gtk_main_quit();
}

void on_togglebutton1_toggled()
{
	if(toggleChange==1){
		gtk_widget_show(image);
		toggleChange=0;
	}else{
		gtk_widget_hide(image);
		toggleChange=1;
	}
	printf("%d\n",toggleChange);
}
